package com.example.dllo.exe.fenlei.gonglue;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.bean.GongLueRvBean;
import com.example.dllo.exe.fengzhuang.NetTool;
import com.example.dllo.exe.remen.ReMenRvAdapter;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class GongLueLanMuChaKanQuanBuAdapter extends RecyclerView.Adapter<GongLueLanMuChaKanQuanBuAdapter.MyViewHolder> {
    private GongLueRvBean gongLueRvBean;
    private Context context;

    public void setGongLueRvBean(GongLueRvBean gongLueRvBean) {
        this.gongLueRvBean = gongLueRvBean;
        notifyDataSetChanged();
    }

    public GongLueLanMuChaKanQuanBuAdapter(Context context) {
        this.context = context;
    }

    @Override
    public GongLueLanMuChaKanQuanBuAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.gongluelanmuchakanquanbu,parent,false);
       MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(GongLueLanMuChaKanQuanBuAdapter.MyViewHolder holder, int position) {
        NetTool netTool=new NetTool();
        netTool.getImage(gongLueRvBean.getData().getColumns().get(position).getCover_image_url(),holder.coverimageurl);
        try {
            holder.titleuptitle.setText(gongLueRvBean.getData().getColumns().get(position).getTitle());
            holder.subtitleuptitle.setText(gongLueRvBean.getData().getColumns().get(position).getSubtitle());
            holder.authoruptitle.setText(gongLueRvBean.getData().getColumns().get(position).getAuthor());
        }catch (NullPointerException e){
            Log.d("gongluelanmuchakana", "adapter"+position);
        }
    }

    @Override
    public int getItemCount() {
        return gongLueRvBean!=null?gongLueRvBean.getData().getColumns().size():0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView titleuptitle;
        TextView subtitleuptitle;
        TextView authoruptitle;
        ImageView coverimageurl;
        public MyViewHolder(View itemView) {
            super(itemView);
            titleuptitle= (TextView) itemView.findViewById(R.id.title_textrv);
            subtitleuptitle= (TextView) itemView.findViewById(R.id.subtitle_textrv);
            authoruptitle= (TextView) itemView.findViewById(R.id.author_textrv);
            coverimageurl= (ImageView) itemView.findViewById(R.id.coverimage_iv);

        }
    }
}
